/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.assertj.ohos.api.components.element;

import ohos.media.image.PixelMap;
import ohos.media.image.common.AlphaType;
import org.assertj.core.api.AbstractAssert;

import static org.assertj.core.api.Assertions.assertThat;

/** Assertions for {@link PixelMap} instances. */
public class PixelMapAssert extends AbstractAssert<PixelMapAssert, PixelMap> {
    public PixelMapAssert(PixelMap actual) {
    super(actual, PixelMapAssert.class);
    }

    /**
    * 是否回收
    *
    * @return PixelMapAssert
    */
    public PixelMapAssert isRecycled() {
    isNotNull();
    assertThat(actual.isReleased()) //
        .overridingErrorMessage("Expected to be recycled but was not recycled.") //
        .isTrue();
    return this;
    }

    /**
    * 是否不回收
    *
    * @return PixelMapAssert
    */
    public PixelMapAssert isNotRecycled() {
    isNotNull();
    assertThat(actual.isReleased()) //
        .overridingErrorMessage("Expected to not be recycled but was recycled.") //
        .isFalse();
    return this;
    }

    /**
    * 是否可变
    *
    * @return PixelMapAssert
    */
    public PixelMapAssert isMutable() {
    isNotNull();
    assertThat(actual.isEditable()) //
        .overridingErrorMessage("Expected to be mutable but was not mutable.") //
        .isTrue();
    return this;
    }

    /**
    * 是否不可变
    *
    * @return PixelMapAssert
    */
    public PixelMapAssert isNotMutable() {
    isNotNull();
    assertThat(actual.isEditable()) //
        .overridingErrorMessage("Expected to not be mutable but was mutable.") //
        .isFalse();
    return this;
    }

    /**
    * 是否预乘
    *
    * @return PixelMapAssert
    */
    public PixelMapAssert isPremultiplied() {
    isNotNull();
    boolean isPremultiplied = actual.getImageInfo().alphaType == AlphaType.PREMUL;
    assertThat(isPremultiplied) //
        .overridingErrorMessage("Expected to be premultiplied but was not premultiplied.") //
        .isTrue();
    return this;
    }

    /**
    * 是否不预乘
    *
    * @return PixelMapAssert
    */
    public PixelMapAssert isNotPremultiplied() {
    isNotNull();
    boolean isPremultiplied = actual.getImageInfo().alphaType == AlphaType.PREMUL;
    assertThat(isPremultiplied) //
        .overridingErrorMessage("Expected to not be premultiplied but was premultiplied.") //
        .isFalse();
    return this;
    }

    /**
    * 分配字节数
    *
    * @param count 数量
    * @return PixelMapAssert
    */
    public PixelMapAssert hasAllocationByteCount(long count) {
    isNotNull();
    long actualCount = actual.getPixelBytesCapacity();
    assertThat(actualCount) //
        .overridingErrorMessage("Expected allocation byte count <%s> but was <%s>.", count,
            actualCount) //
        .isEqualTo(count);
    return this;
    }

    /**
    * 占用字节数
    *
    * @param count 数量
    * @return PixelMapAssert
    */
    public PixelMapAssert hasByteCount(long count) {
    isNotNull();
    long actualCount = actual.getPixelBytesNumber();
    assertThat(actualCount) //
        .overridingErrorMessage("Expected byte count <%s> but was <%s>.", count, actualCount) //
        .isEqualTo(count);
    return this;
    }

    /**
    * 密度
    *
    * @param density 密度
    * @return PixelMapAssert
    */
    public PixelMapAssert hasDensity(int density) {
    isNotNull();
    int actualDensity = actual.getBaseDensity();
    assertThat(actualDensity) //
        .overridingErrorMessage("Expected density <%s> but was <%s>.", density, actualDensity) //
        .isEqualTo(density);
    return this;
    }

    /**
    * 宽
    *
    * @param width 宽
    * @return PixelMapAssert
    */
    public PixelMapAssert hasWidth(int width) {
    isNotNull();
    int actualWidth = actual.getImageInfo().size.width;
    assertThat(actualWidth) //
        .overridingErrorMessage("Expected width <%s> but was <%s>.", width, actualWidth) //
        .isEqualTo(width);
    return this;
    }

    /**
    * 高
    *
    * @param height 高
    * @return PixelMapAssert
    */
    public PixelMapAssert hasHeight(int height) {
    isNotNull();
    int actualHeight = actual.getImageInfo().size.height;
    assertThat(actualHeight) //
        .overridingErrorMessage("Expected height <%s> but was <%s>.", height, actualHeight) //
        .isEqualTo(height);
    return this;
    }

    /**
    * 具有Alpha支持
    *
    * @return PixelMapAssert
    */
    public PixelMapAssert hasAlphaSupport() {
    isNotNull();
    assertThat(actual.getImageInfo().alphaType != AlphaType.OPAQUE) //
        .overridingErrorMessage("Expected to have alpha support but did not have it.") //
        .isTrue();
    return this;
    }

    /**
    * 没有Alpha支持
    *
    * @return PixelMapAssert
    */
    public PixelMapAssert hasNoAlphaSupport() {
    isNotNull();
    assertThat(actual.getImageInfo().alphaType != AlphaType.OPAQUE) //
        .overridingErrorMessage("Expected to not have alpha support but had it.") //
        .isFalse();
    return this;
    }
}
